package thread;

/**
 * 多线程
 */
public class Thread03 {

    public static void main(String[] args) {
        /*
            编写一个程序，创建两个线程，一个线程每隔1秒输出 "hello,world"，输出10次退出
            一个线程每隔1秒输出"hi"，输出5次退出
         */

        T1 t1 = new T1();
        Tt2 tt2 = new Tt2();
        Thread thread1 = new Thread(t1);
        Thread thread2 = new Thread(tt2);
        thread1.start();    //启动第一个线程
        thread2.start();    //启动第二个线程
    }
}

class T1 implements Runnable {
    int count = 0;
    @Override
    public void run() {
        //每隔1秒输出 “hi”,输出5次
        while (true) {
            System.out.println("hello,world " + (++count));
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            if(count == 10) {
                break;
            }
        }
    }
}


class Tt2 implements Runnable {
    int count = 0;
    @Override
    public void run() {
        //每隔1秒输出 “hi”,输出5次
        while (true) {
            System.out.println("hi " + (++count));
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            if(count == 5) {
                break;
            }
        }
    }
}